package com.poker.controller;

import com.poker.consts.Consts;
import com.poker.entity.ProductOrder;
import com.poker.service.ProductOrderService;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * @ClassName ProductOrderController
 * @Description TODO
 * @Author duyuanyuan
 * @Date 2019/3/13 13:26
 * @Version 1.0
 **/
@Controller
@RequestMapping("/productOrder")
public class ProductOrderController extends BaseController {

    @Resource
    private ProductOrderService productOrderService;

    @RequestMapping("/list")
    public String list(Model model, ProductOrder productOrder,
                       @RequestParam(defaultValue = "0") Integer page,
                       @RequestParam(defaultValue = "10") Integer size) {
        Page<ProductOrder> data = productOrderService.findAllProduct(page, size);

        model.addAttribute("data", data);
        model.addAttribute("productOrder", productOrder);
        return managerPage("productOrder/list");
    }

    @RequestMapping("/edit")
    public String edit(Model model, String id, String editType) {
        ProductOrder productOrder = new ProductOrder();

        if (Consts.EditType.EDIT.equals(editType)) productOrder = productOrderService.getById(id);

        model.addAttribute("productOrder", productOrder);
        model.addAttribute("editType", editType);
        return managerPage("productOrder/edit");
    }

    @RequestMapping("/findQuery")
    public String findQuery(Model model , ProductOrder productOrder,
                            @RequestParam(defaultValue = "0") Integer page,
                            @RequestParam(defaultValue = "10") Integer size) {
        Page<ProductOrder> data = productOrderService.queryProductOrder(page, size, productOrder);

        model.addAttribute("data", data);
        model.addAttribute("productOrder", productOrder);
        return managerPage("productOrder/list");
    }
}
